<template>
  <div class="hero-game">
    <h2>🎮 勇者大冒险</h2>
    <div class="hero-status">
      <h3>勇者血量：{{ hp }}</h3>
      <div class="hp-bar">
        <div class="hp-fill" :style="{ width: hp + '%' }"></div>
      </div>
      <p class="hp-text">{{ hp }}/100</p>
    </div>
    
    <button 
      @click="attack" 
      :disabled="attacking || hp <= 0"
      :class="{ 'attacking': attacking }"
    >
      {{ attacking ? '⚔️ 攻击中...' : '⚔️ 发起攻击' }}
    </button>
    
    <div v-if="hp <= 0" class="game-over">
      <p>💀 勇者战败了！</p>
      <button @click="reset">🔄 重新开始</button>
    </div>
    
    <div class="game-tips">
      <p>💡 小贴士：每次攻击消耗20点血量</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// 创建响应式数据 - 英雄血量
const hp = ref(100)
const attacking = ref(false)

// 攻击函数
const attack = () => {
  if (hp.value <= 0) return
  
  attacking.value = true
  
  // 模拟攻击过程
  setTimeout(() => {
    hp.value -= 20
    attacking.value = false
    
    // 检查游戏状态
    if (hp.value <= 0) {
      console.log('游戏结束！勇者战败了！')
    }
  }, 500)
}

// 重置游戏
const reset = () => {
  hp.value = 100
  attacking.value = false
}
</script>

<style scoped>
.hero-game {
  max-width: 400px;
  margin: 50px auto;
  padding: 30px;
  border: 2px solid #42b883;
  border-radius: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  font-family: 'Arial', sans-serif;
}

.hero-status {
  margin: 20px 0;
}

.hp-bar {
  width: 100%;
  height: 20px;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b6b, #ee5a24);
  transition: width 0.3s ease;
  border-radius: 10px;
}

.hp-text {
  font-size: 14px;
  margin: 5px 0;
}

button {
  padding: 12px 24px;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  background: #42b883;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 10px;
}

button:hover:not(:disabled) {
  background: #369870;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

button:disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
}

button.attacking {
  background: #ff6b6b;
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.game-over {
  margin: 20px 0;
  padding: 15px;
  background: rgba(255, 0, 0, 0.2);
  border-radius: 10px;
  border: 1px solid rgba(255, 0, 0, 0.5);
}

.game-tips {
  margin-top: 20px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 12px;
}
</style>